import request from '@/utils/request'

/**
 * 管理员服务
 * @type {{deleteAdmin: (function(*): *), logout: (function(): *), editPwd: (function(*=): *), addAdmin: (function(*=): *), login: (function(*=): *), getUserInfo: (function(): *), listAdmin: (function(*): *), editAdmin: (function(*=): *)}}
 */
export const AdminService = {
  // 登录
  login: function(params) { return request({ method: 'post', url: '/manage/admin/login.do', data: params }) },
  // 登出
  logout: function() { return request({ method: 'get', url: '/manage/admin/logout.do' }) },
  // 当前登录用户信息
  getUserInfo: function() { return request({ method: 'get', url: '/manage/admin/currentInfo.do' }) },
  // 管理员列表
  listAdmin: function(query) { return request({ method: 'get', url: '/manage/admin/list.do', params: { ...query }}) },
  // 新增管理员
  addAdmin: function(data) { return request({ method: 'post', url: '/manage/admin/add.do', data: data }) },
  // 编辑管理员信息
  editAdmin: function(data) { return request({ method: 'post', url: '/manage/admin/edit.do', data: data }) },
  // 删除管理员信息
  deleteAdmin: function(id) { return request({ method: 'post', url: '/manage/admin/delete.do', data: [id] }) },
  // 密码修改
  editPwd: function(data) { return request({ method: 'post', url: '/manage/admin/edit/pwd.do', data: data }) }
}

/**
 * 系统菜单服务
 * @type {{editMenu: (function(*=): *), deleteMenu: (function(*): *), listMenus: (function(): *), addMenu: (function(*=): *), listMenuNames: (function(): *)}}
 */
export const MenuService = {
  // 系统菜单列表
  listMenus: function() { return request({ method: 'get', url: '/manage/menu/list.do' }) },
  listMenuNames: function() { return request({ method: 'get', url: '/manage/menu/all.do' }) },
  // 添加系统菜单
  addMenu: function(formData) { return request({ method: 'post', url: '/manage/menu/add.do', data: formData }) },
  // 编辑系统菜单
  editMenu: function(formData) { return request({ method: 'post', url: '/manage/menu/edit.do', data: formData }) },
  // 删除系统菜单
  deleteMenu: function(menuId) { return request({ method: 'post', url: '/manage/menu/delete.do', data: [menuId] }) }
}

/**
 * 系统角色服务
 * @type {{listRole: (function(): *), bindRoleAndMenu: (function(*=, *=): *), listRoleNames: (function(): *), editRole: (function(*=): *), deleteRole: (function(*): *), getMenuByRole: (function(*=): *), addRole: (function(*=): *)}}
 */
export const RoleService = {
  // 角色列表
  listRoleNames: function() { return request({ method: 'get', url: '/manage/role/all.do' }) },
  // 角色列表
  listRole: function() { return request({ method: 'get', url: '/manage/role/list.do' }) },
  // 新增角色
  addRole: function(data) { return request({ method: 'post', url: '/manage/role/add.do', data: data }) },
  // 编辑角色
  editRole: function(data) { return request({ method: 'post', url: '/manage/role/edit.do', data: data }) },
  // 删除角色
  deleteRole: function(id) { return request({ method: 'post', url: '/manage/role/delete.do', data: [id] }) },
  // 获得角色的权限信息
  getMenuByRole: function(roleId) { return request({ method: 'get', url: '/manage/role/menus.do', params: { roleId: roleId }}) },
  // 角色和权限绑定
  bindRoleAndMenu: function(roleId, menuIds) { return request({ method: 'post', url: '/manage/role/bind.do', params: { roleId: roleId }, data: menuIds }) }
}
